﻿package com.badibadi.activity;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.tsz.afinal.FinalBitmap;

import org.json.JSONException;

import com.badibadi.adapter.AddingRecordNewAdapter;
import com.badibadi.adapter.AreaAdapter;
import com.badibadi.infos.ListsModel;
import com.badibadi.infos.Results;
import com.badibadi.infos.UserInfoModel;
import com.badibadi.mytools.AreaDialog;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.CropPictureTools;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.InterestModel;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MySharePreferences;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.SelectPicLayoutActivity;
import com.badibadi.mytools.UserDataSet;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.WidgetUtils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.ShowErWeiMaActivity;
import com.libjph.util.StringUtil;
//import com.lidroid.xutils.util.LogUtils;
import com.view.my_view.XGridView;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
//RL6drlx
//ExpertApply  InterestSelectActivity  l13 参考咨询费 地区id 18 lz 设置来自 RL4_ckzxf

public class MyDataActivity extends BaseActivity implements OnClickListener {// AboutConsultingFees

	protected static final int ErWeiMaZD = 9000;
	/**
	 * 第一次弹出来的设置兴趣爱好 post
	 */
	private int GridViewNumColumns = 4;
	private int PopWindowsW = 300;
	private int PopWindowsH = 400;
	/**
	 * 是否是第一次注册登录
	 */
	private boolean isFirstRegirstration = false;

	private Button return_btn;

	// 检测时间间隔
	private int detchTime = 5;

	private Map<Integer, String> TitleMap;
	private ListsModel listsModel;
	public Button ApplyFor;
	/**
	 * 这是传过来的id
	 */
	String id = "41";// 26
	// 所有的Reativelayoutid（注意：有更多关于我）男
	private int[] btn_id = new int[] { R.id.RL0touxiang, R.id.RL1mingcheng,
			R.id.RL3_xqah, R.id.RL4_ckzxf, R.id.RL5zcjs, R.id.RL6drlx,
			R.id.RL7zym, R.id.RL8lz, R.id.RL9yx, R.id.RL10xb, R.id.R_zfb,
			R.id.R_jbye, R.id.R_csrq, R.id.R_sjhm, R.id.R_bgt, R.id.Ri_gdgyw,
			R.id.Ri_zxcjdjlb, R.id.Ri_ztydjlb, R.id.Ri_wdewm, R.id.Ri_xlbj,
			R.id.R_zfbyhmc };
	// 左边的Text
	private int[] Left_Textid = new int[] { R.id.l0, R.id.l1, R.id.l2, R.id.l3,
			R.id.l4, R.id.l5, R.id.l6, R.id.l7, R.id.l8, R.id.l9, R.id.l10,
			R.id.l11, R.id.l12, R.id.l13, R.id.l14, R.id.gdgyw, R.id.l16,
			R.id.l17, R.id.l18, R.id.l19, R.id.l20 };
	// 右边的text和头像的Id
	private int[] TextOrimg_Id = new int[] { R.id.touxiang, R.id.mingcheng,
			R.id.xqah, R.id.ckzxf, R.id.zcjs, R.id.drlx, R.id.zym, R.id.lz,
			R.id.yx, R.id.xb, R.id.zfbzh, R.id.jbye, R.id.csrq, R.id.sjhm,
			R.id.beijingtu, R.id.gdgyw, R.id.zxcjdjlb, R.id.ztydjlb,
			R.id.myErweima, R.id.xlbj, R.id.zfbyhmc };

	/**
	 * 三张
	 */
	private List<ImageView> iv;

	/**
	 * 三张
	 */
	// private List<TextView> tv; send
	private FinalBitmap finalbitmap;
	/**
	 * 头像
	 */
	private final int IMG_CROP_HEAD = 0;
	/**
	 * 背景图
	 */
	private final int IMG_CROP_BEIJING = 1;
	/**
	 * 配合iv_image判定是哪一个
	 */
	private int temp = -1;

	private PopupWindow mpWindow;

	private int minMoneyNumber = 10;

	private UserInfoModel userInfoModel;

	private UserDataSet userDataSet;
	private AddingRecordNewAdapter arnAdapter;
	private AreaDialog areaDialog;
	private int languageType = 0;
	private MySharePreferences preferences;
	private AreaAdapter areaAdapter;

	/**
	 * 图片的uri
	 */
	private static String uri0;
	private static String uri1;
	private String language;
	PopupWindow pop;// 第一次登录用户进入到这个界面，填写兴趣爱好

	UserDataSet userSet;
	android.os.Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 6:
				Utils.ExitPrgress(MyDataActivity.this);
				RefreshData();// 更新数据
				break;
			case 2:
				Utils.ExitPrgress(MyDataActivity.this);
				ShowToast(MyDataActivity.this,
						getResources().getString(R.string.l_net_error));
				break;
			case 5:
				Utils.ExitPrgress(MyDataActivity.this);
				Utils.showMessage(MyDataActivity.this, getResources()
						.getString(R.string.l_net_error));
				break;
			case 8:
				Utils.ExitPrgress(MyDataActivity.this);
				if (arnAdapter != null) {
					arnAdapter.notifyDataSetChanged();
				}
				break;
			case 9:
				Utils.ExitPrgress(MyDataActivity.this);
				Utils.showMessage(MyDataActivity.this, getResources()
						.getString(R.string.l_xa10));
				break;
			case 1:
				Utils.ExitPrgress(MyDataActivity.this);
				areaDialog.AreaDisplayDialog();
				areaAdapter = new AreaAdapter(MyDataActivity.this,
						areaDialog.areaModelscountry);
				areaDialog.holderView.area_country_name_spinner
						.setAdapter(areaAdapter);
				break;
			case 3:
				Utils.ExitPrgress(MyDataActivity.this);
				areaAdapter = new AreaAdapter(MyDataActivity.this,
						areaDialog.areaModelssheng);
				areaDialog.holderView.area_province_name_spinner
						.setAdapter(areaAdapter);
				break;
			case 4:
				Utils.ExitPrgress(MyDataActivity.this);
				areaAdapter = new AreaAdapter(MyDataActivity.this,
						areaDialog.areaModelscity);
				areaDialog.holderView.area_city_name_spinner
						.setAdapter(areaAdapter);
				break;
			case 7:
				Utils.ExitPrgress(MyDataActivity.this);
				String area[] = msg
						.getData()
						.getString("来自",
								getResources().getString(R.string.l_x2))
						.split(" ");
				if (area != null && area.length > 0) {
					((TextView) (findViewById(TextOrimg_Id[7])))
							.setText(area[0] + " " + area[1] + " " + area[2]);
					userInfoModel.setArea_id(area[3]);
					userDataSet.UserDataSet2(userInfoModel, 0, "", true);
				} else {
					((TextView) (findViewById(TextOrimg_Id[7])))
							.setText(getResources().getString(R.string.l_x2));
				}
				break;
			case 10:
				break;
			case 11:
				break;
			case 12:
				try {
					settingPopWindow();
					// LogUtils.d("" + "运行了4");
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			}
		};
	};
	private List<InterestModel> Interestlist;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		// android4Detail();
		setContentView(R.layout.my_data);
		Constants.is_shuaxin = false;
		id = getIntent().getStringExtra("uid");
		if (id == null) {
			id = Utils.getUid(MyDataActivity.this);
		}
		userSet = new UserDataSet(MyDataActivity.this);
		iv = new ArrayList<ImageView>();
		Interestlist = new ArrayList<InterestModel>();
		// tv = new ArrayList<TextView>();
		userDataSet = new UserDataSet(this);

		finalbitmap = FinalBitmap.create(this);
		finalbitmap.configLoadfailImage(R.drawable.aah);
		finalbitmap.configLoadingImage(R.drawable.aah);

		PopWindowsW = (int) getScreenSize(SCREENW) / 2;
		PopWindowsH = (int) getScreenSize(SCREENH) / 2;
		preferences = new MySharePreferences(getApplicationContext(),
				"language");
		languageType = preferences.get("language", 0);
		// init();
		// Utils.showPrgress(MyDataActivity.this);
		Thread t = new Thread(new RefreshDataThread());
		t.start();
		if (isFirstLogin()) {
			// LogUtils.d("" + "运行了1");
			Interest();
		}

	}

	/**
	 * 一、这里是从网络上下载数据
	 * 
	 * @author Administrator
	 * 
	 */
	public class RefreshDataThread implements Runnable {
		@Override
		public void run() {
			// TODO Auto-generated method stub

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", id);
			map.put("languageType", com.badibadi.mytools.Dialog
					.getSystemLanguageType(MyDataActivity.this));
			String content = Utils.sendRequest(map, Constants.BadiUrl
					+ "userDataShow");
			//
			if (content != null) {
				// ("结果是:" + content);
				Results results = Utils.checkResult_NNN(
						getApplicationContext(), content);
				if (results != null && results.getRetmsg() != null) {
					//
					// ("得到的结果是：" + results.getRetmsg());
					try {
						userInfoModel = JSONUtils.getEntityByJsonString(
								results.getRetmsg(), UserInfoModel.class);
						userInfoModel.setUid(id);
						mHandler.sendEmptyMessage(6);

					} catch (JSONException e) {
						// ("解析出错");

					} catch (Exception e) {
						// TODO Auto-generated catch block
						//

					}
				} else {

				}
			} else {
				Utils.ExitPrgress(MyDataActivity.this);
				mHandler.sendEmptyMessage(2);
			}
		}

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Thread t = new Thread(new RefreshDataThread());
		t.start();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		if (Constants.is_shuaxin) {
			Thread t = new Thread(new RefreshDataThread());
			t.start();
			Constants.is_shuaxin = false;
		}
	}

	/**
	 * 二、更新界面上显示的数据
	 */
	protected void RefreshData() {
		init();
		if (userInfoModel.getIs_expert().equals("1")) {
			ApplyFor.setVisibility(View.GONE);
		} else {
			ApplyFor.setVisibility(View.VISIBLE);
		}
		for (int i = 0; i < TextOrimg_Id.length; i++) {
			//
			String str = "";
			if (i == 0 || i == 14 || i == 18) {
				iv.add((ImageView) (findViewById(TextOrimg_Id[i])));
				//
				//
				// "----------------->" + userInfoModel.getInfo_head());
				if (i == 0 && userInfoModel.getHead() != null
						&& !(userInfoModel.getHead().equals(""))
						&& !(userInfoModel.getHead().equals("null")))// 头像
				{
					//
					// + userInfoModel.getHead().indexOf("."));

					if (userInfoModel.getHead().indexOf(".") == 0
							|| userInfoModel.getHead().indexOf(".") == 1) {
						str = userInfoModel.getHead().substring(
								userInfoModel.getHead().indexOf("."),
								userInfoModel.getHead().length());
						userInfoModel.setHead(str);
						//
					}
					finalbitmap.display(iv.get(0), Constants.BadiDownImgUrl
							+ userInfoModel.getHead() + Constants.App9block);// ,BitmapFactory.decodeResource(getResources(),
					// R.drawable.aah),BitmapFactory.decodeResource(getResources(),
					// R.drawable.aah)

				} else if (i == 14
						&& userInfoModel.getInfo_head() != null
						&& !(userInfoModel.getInfo_head().equals(""))
						&& !(userInfoModel.getInfo_head().equals("null") && userInfoModel
								.getInfo_head().length() > 2))// 背景图// ||
																// userInfoModel.getInfo_head().trim().length()<=0)
				{
					//
					//
					// "getInfo_head=====>" + userInfoModel.getInfo_head());
					if (userInfoModel.getInfo_head().indexOf(".") == 0
							|| userInfoModel.getInfo_head().indexOf(".") == 1) {
						str = "";
						str = userInfoModel.getInfo_head().substring(
								userInfoModel.getInfo_head().indexOf("."),
								userInfoModel.getInfo_head().length());
						userInfoModel.setInfo_head(str);
					}
					//
					finalbitmap.display(iv.get(1), Constants.BadiDownImgUrl
							+ userInfoModel.getInfo_head()
							+ Constants.Appactivitycover);
				} else if (i == 18)// 我的二维码
				{
					// if (userInfoModel.getInfo_head().indexOf(".") == 0
					// || userInfoModel.getInfo_head().indexOf(".") == 1) {
					// str = "";
					// str = userInfoModel.getInfo_head().substring(
					// userInfoModel.getInfo_head().indexOf("."),
					// userInfoModel.getInfo_head().length());
					// userInfoModel.setInfo_head(str);
					// }
					// finalbitmap.display(iv.get(2), Constants.BadiDownImgUrl
					// + userInfoModel.getInfo_head());
					Bitmap bmp = Utils.getGeRenErWerMa(id,
							DisplayUtil.dip2px(this, 80),
							DisplayUtil.dip2px(this, 80));
					iv.get(2).setImageBitmap(bmp);

				}
			} else if (i != 15) {
				switch (i) {
				case 1:
					if (userInfoModel.getNickName() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getNickName());
					break;
				case 2:
					if (userInfoModel.getTypeName() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getTypeName());
					break;
				case 3:
					if (userInfoModel.getAdvisory_fees() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getAdvisory_fees());
					break;
				case 4:
					if (userInfoModel.getSpeciality() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getSpeciality());
					break;
				case 5:
					if (userInfoModel.getExpert_typeid_name() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getExpert_typeid_name());
					break;
				case 6:
					if (userInfoModel.getMotto() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getMotto());
					break;
				case 7:
					((TextView) (findViewById(TextOrimg_Id[i]))).setText(""
							+ userInfoModel.getSavename() + " "
							+ userInfoModel.getCityname());
					break;
				case 8:
					if (userInfoModel.getEmail() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getEmail());

					break;
				case 9:
					String sex = getResources().getString(R.string.l_xb144);
					if (userInfoModel.getSex().equals("0"))
						sex = getResources().getString(R.string.l_xb144);
					if (userInfoModel.getSex().equals("1"))
						sex = getResources().getString(R.string.l_x4);
					if (userInfoModel.getSex().equals("2"))
						sex = getResources().getString(R.string.l_x3);
					((TextView) (findViewById(TextOrimg_Id[i]))).setText(sex);

					break;
				case 10:
					if (userInfoModel.getAlipay() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getAlipay());

					break;
				case 11:
					if (userInfoModel.getGold() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getGold());

					break;
				case 12:
					if (userInfoModel.getBirthday() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getBirthday());
					break;
				case 13:
					if (userInfoModel.getPhone() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getPhone());
					break;

				case 16:
					if (userInfoModel.getLike_club() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getLike_club());

					break;
				case 17:
					if (userInfoModel.getUnlike_club() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getUnlike_club());

					break;
				case 19:
					if (userInfoModel.getEducation() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getEducation());

					break;
				case 20:
					if (userInfoModel.getAlipayName() != null)
						((TextView) (findViewById(TextOrimg_Id[i])))
								.setText(userInfoModel.getAlipayName());

					break;

				}
			}
		}
		Utils.ExitPrgress(MyDataActivity.this);

	}

	private void init() {
		// TODO Auto-generated method stub
		ApplyFor = (Button) this.findViewById(R.id.ApplyFor);
		ApplyFor.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MyDataActivity.this,
						DataSetChoseExpertApplyForTypeActivity.class);
				intent.putExtra("userInfoModel", userInfoModel);
				startActivity(intent);
			}
		});
		// this.findViewById(R.id.my_data_return_btn).setOnClickListener(
		// new OnClickListener() {
		//
		// @Override
		// public void onClick(View arg0) {
		// // TODO Auto-generated method stub
		// finish();
		// }
		// });
		return_btn = (Button) this.findViewById(R.id.my_data_return_btn);
		return_btn.setOnClickListener(this);
		areaDialog = new AreaDialog(MyDataActivity.this, languageType, mHandler);
		initData();

	}

	// 初始化资源并且侦听
	protected void initData() {
		// TODO Auto-generated method stub
		for (int i = 0; i < btn_id.length; i++) {
			final int ii = i;
			this.findViewById(btn_id[i]).setOnClickListener(
					new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							// 头像 背景图 和我的二维码 三个
							if (v.getId() == btn_id[0]) {
								Intent intent = new Intent(MyDataActivity.this,
										SelectPicLayoutActivity.class);
								intent.putExtra("CUTTING", "no");
								startActivityForResult(intent, IMG_CROP_HEAD);
							} else if (v.getId() == btn_id[14]) {
								Intent intent = new Intent(MyDataActivity.this,
										SelectPicLayoutActivity.class);
								intent.putExtra("Cutting", "yes");// 传入是否需要裁剪的参数，传则不需要，不传则需要
								startActivityForResult(intent, IMG_CROP_BEIJING);

							} else if (v.getId() == btn_id[18]) {

								Intent intent = new Intent(MyDataActivity.this,
										ShowErWeiMaActivity.class);
								intent.putExtra("erweima",
										Utils.getGeRenErWeiMa(id));
								startActivityForResult(intent, ErWeiMaZD);

							}

							else if (v.getId() == btn_id[2])// /在这里设置特殊的，(兴趣爱好)
							{
								Intent intent = new Intent(MyDataActivity.this,
										InterestSelectActivity.class);
								intent.putExtra("MyDataActivity", userInfoModel);
								intent.putExtra("typeid",
										userInfoModel.getTypeid());
								startActivity(intent);// , 0x26
								MyDataActivity.this.finish();
							} else if (v.getId() == btn_id[3])// 设置参考咨询费
							{
								LoadingPopWindows();
							} else if (v.getId() == btn_id[5])// /选择达人种类
							{
								if (userInfoModel.getIs_expert().equals("0")) {
									Intent intent = new Intent(
											MyDataActivity.this,
											DataSetChoseExpertApplyForTypeActivity.class);
									intent.putExtra("userInfoModel",
											userInfoModel);
									startActivity(intent);
								} else {

								}

							} else if (v.getId() == btn_id[7])// 这是设置来自
							{
								// Utils.showPrgress(MyDataActivity.this);
								areaDialog.Getareathread();
							} else if (v.getId() == btn_id[8]) {

							} else if (v.getId() == btn_id[9])// 修改性别
							{
								setSexDialog(MyDataActivity.this);
								setOnMyDialogeClistener(new OnMyDialogeClistener() {

									@Override
									public void Ok() {
										// TODO Auto-generated method stub
										// TextView t = (TextView)
										// findViewById(TextOrimg_Id[9]);
										// t.setText("" + getSex());
										if (getSex().equals(
												getResources().getString(
														R.string.l_x4))) {
											userInfoModel.setSex("1");

										} else if (getSex().equals(
												getResources().getString(
														R.string.l_x3))) {
											userInfoModel.setSex("2");

										} else {
											userInfoModel.setSex("0");

										}
										// if()
										// {
										userDataSet.UserDataSet2(userInfoModel,
												0, "", true);

										// };

									}

									@Override
									public void Cancle() {
										// TODO Auto-generated method stub

									}
								});
							} else if (v.getId() == btn_id[11])// 这是金币余额
							{
								Intent intent = new Intent(MyDataActivity.this,
										RechargeActivity.class);
								startActivity(intent);
							} else if (v.getId() == btn_id[12])// 修改年月日有问题
							{
								com.badibadi.mytools.Dialog dialog = new com.badibadi.mytools.Dialog();
								dialog.setOnDataChangeClistener(new com.badibadi.mytools.Dialog.UserDateDialogClistener() {

									@Override
									public void ok() {
										// TODO Auto-generated method stub
										RefreshData();
									}
								});
								dialog.createDateDialog(MyDataActivity.this,
										userInfoModel);
							} else // 其余的都是text(15（更多关于我除外）)
							if (v.getId() == btn_id[ii]
									&& v.getId() != btn_id[15]) {
								Intent intent = new Intent(MyDataActivity.this,
										ModifyTheMyDataActivity.class);
								intent.putExtra("id", ii);
								TextView t1 = (TextView) findViewById(TextOrimg_Id[ii]);
								intent.putExtra("KEY" + ii, t1.getText()
										.toString().trim());
								t1 = (TextView) findViewById(Left_Textid[ii]);
								intent.putExtra("STR" + ii, t1.getText()
										.toString().trim());

								intent.putExtra("UseInfoModel", userInfoModel);
								// intent.putExtra(name, value)

								startActivityForResult(intent,
										((ii * 1000) + ii));
								overridePendingTransition(R.anim.slide_left,
										R.anim.slide_right);
							}
						}
					});
		}

	}

	/**
	 * 返回一个是否是第一次登录 第一次登录要设置popwindow =======
	 * 
	 * @return true 是 false 否
	 */
	protected boolean isFirstLogin() {
		// 如果是第一次注册并且登录
		if (Constants.model.getAmount() != null) {
			if (Integer.parseInt(Constants.model.getAmount()) <= 1)
				return true;
			else
				return false;
		}
		return false;
	}

	private void Interest() {
		// Utils.showPrgress(MyDataActivity.this);

		// LogUtils.d("" + "运行了2");
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				listsModel = new ListsModel();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("type", "xingqu");
				map.put("languageType",
						Dialog.getSystemLanguageType(MyDataActivity.this));
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "type/listType");
				if (content != null) {
					// ("结果是:" + content);
					Results results = Utils.checkResult_NNN(
							getApplicationContext(), content);
					if (results != null && results.getRetmsg() != null) {
						//
						try {
							if (results.isRet() == true) {
								// LogUtils.d("" + "运行了3");
								listsModel = JSONUtils.getEntityByJsonString(
										results.getRetmsg(), ListsModel.class);
								mHandler.sendEmptyMessage(12);
							} else {
								mHandler.sendEmptyMessage(2);
							}

						} catch (Exception e) {
							// TODO Auto-generated catch block
							//

							// mHandler.sendEmptyMessage(12);
						}
					} else {
						mHandler.sendEmptyMessage(11);
					}
				} else {
					mHandler.sendEmptyMessage(10);
				}
			}
		});
	}

	/**
	 * 显示一个popwindow
	 */
	private void settingPopWindow() {
		// TODO Auto-generated method stub
		if (Interestlist != null) {
			Interestlist.clear();
		}
		if (listsModel.getLists() != null && !listsModel.getLists().isEmpty()) {
			Interestlist.addAll(listsModel.getLists());
		}
		LayoutInflater inflater = LayoutInflater.from(MyDataActivity.this);
		View root = inflater.inflate(R.layout.my_data_interesting_like, null);
		TextView finish = (TextView) root.findViewById(R.id.finish);
		XGridView gv = (XGridView) root.findViewById(R.id.xgridview);
		arnAdapter = new AddingRecordNewAdapter(MyDataActivity.this,
				Interestlist);
		finish.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				List<String> mlist = new ArrayList<String>();
				if (userInfoModel != null) {
					if (!TitleMap.isEmpty()) {
						for (Map.Entry<Integer, String> entry : TitleMap
								.entrySet()) {
							// ("key= " + entry.getKey()
							// + " and value= " + entry.getValue());
							mlist.add(entry.getValue());
						}
						String str = "";
						//
						if (mlist != null) {
							for (int i = 0; i < mlist.size(); i++) {
								if (i == 0) {
									str = mlist.get(i);
								} else {
									str = str + "," + mlist.get(i);
								}
							}
						}
						//

						userInfoModel.setTypeid(str);

						str = "";
						userSet.UserDataSet(userInfoModel, 0, "", true);
					} else {
						ShowToast(getApplicationContext(), getResources()
								.getString(R.string.wx_txt_109));
					}
				} else {
					ShowToast(getApplicationContext(), getResources()
							.getString(R.string.l_net_error));
				}
			}
		});
		gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				if (arnAdapter.getIsItemClick(position) == true) {
					arnAdapter.setIsItemClick(position);
					arnAdapter.notifyDataSetInvalidated();
				} else if (arnAdapter.getSelectNumber() >= arnAdapter
						.getUpperLimit()) {
					ShowToast(MyDataActivity.this,
							getResources().getString(R.string.l_xb4)
									+ arnAdapter.getUpperLimit()
									+ getResources().getString(R.string.l_xb5));
				} else {
					// ShowToast(MyDataActivity.this, "你点击了" + position);
					arnAdapter.setIsItemClick(position);
					arnAdapter.notifyDataSetInvalidated();
				}

				// 在提交按钮将TitleMap提交
				TitleMap = arnAdapter.getTitleMap();
				//
				// Iterator it=TitleMap.entrySet().iterator();
				// while(it.hasNext())
				// {
				// Map.Entry entry=(Map.Entry)it.next();
				// Object key=entry.getKey();
				// Object value=entry.getValue();
				//
				// }
			}
		});

		gv.setNumColumns(GridViewNumColumns);
		gv.setAdapter(arnAdapter);
		pop = new PopupWindow(root, PopWindowsW, PopWindowsH);
		pop.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
		pop.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
		pop.setBackgroundDrawable(new BitmapDrawable());
		pop.setFocusable(true);
		pop.setTouchable(true);
		pop.setOutsideTouchable(true);
		// pop.showAtLocation(findViewById(R.id.ll),
		// Gravity.CENTER, 10, 10);
		Runnable showPopWindowRunnable = new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				// 得到activity中的根元素
				View view = findViewById(R.id.ll);
				// 如何根元素的width和height大于0说明activity已经初始化完毕
				if (view != null && view.getWidth() > 0 && view.getHeight() > 0) {
					// 显示popwindow

					if (pop != null)
						pop.showAtLocation(
								MyDataActivity.this.findViewById(R.id.ll),
								Gravity.CENTER, 0, 0);

					// 停止检测
					mHandler.removeCallbacks(this);
				} else {
					// 如果activity没有初始化完毕则等待5毫秒再次检测
					mHandler.postDelayed(this, detchTime);
				}
			}
		};
		// 开始检测
		mHandler.post(showPopWindowRunnable);
		/****************** 以上代码用来循环检测activity是否初始化完毕 *************/
	}

	/**
	 * 参考咨询费的popwindow
	 */
	private void LoadingPopWindows() {
		final int money = 20;// 不得低于money元
		final Dialog dialog = new Dialog();
		LayoutInflater inflater = LayoutInflater.from(MyDataActivity.this);
		final View root = inflater.inflate(
				R.layout.modify_consulting_fees_popwindow, null);
		(root.findViewById(R.id.Modify_Ok))
				.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub

						if (userInfoModel != null) {
							if (userInfoModel.getAlipay() != null
									&& !("" + userInfoModel.getAlipay())
											.equals("")
									&& userInfoModel.getAlipayName() != null
									&& !("" + userInfoModel.getAlipayName())
											.equals("")) {
								EditText et_edit = (EditText) root
										.findViewById(R.id.et_Advisory_fees);
								if (et_edit.getText().toString().equals("")) {
									Utils.showMessage(
											MyDataActivity.this,
											getResources().getString(
													R.string.l_xb6));
								} else {
									if (Float.parseFloat(et_edit.getText()
											.toString().trim()) < money
											&& Float.parseFloat(et_edit
													.getText().toString()
													.trim()) != 0) {
										Utils.showMessage(
												MyDataActivity.this,
												getResources().getString(
														R.string.l_xb7)
														+ money
														+ getResources()
																.getString(
																		R.string.l_xb8));
									} else {
										userInfoModel.setAdvisory_fees(""
												+ et_edit.getText().toString());

										userDataSet.UserDataSet2(userInfoModel,
												0, "", true);
										dialog.DialogDissMiss();
									}
								}
							} else {
								Utils.showMessage(
										MyDataActivity.this,
										""
												+ getResources().getString(
														R.string.wx_txt_122));
							}

						} else {
							Utils.showMessage(
									MyDataActivity.this,
									""
											+ getResources().getString(
													R.string.l_net_error));
						}

					}
				});
		(root.findViewById(R.id.Modify_Cancle))
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dialog.DialogDissMiss();
					}
				});

		(root.findViewById(R.id.AboutConsultingFees))
				.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(MyDataActivity.this,
								AboutConsultingFeesActivity.class);
						startActivity(intent);
					}
				});

		int h = ((int) (getScreenSize(SCREENH))) / 2;
		String text = String.format(MyDataActivity.this.getResources()
				.getString(R.string.zwckybddy10yyyczlxwdw), 20);
		int index = text.indexOf("20");
		WidgetUtils.setTextTheSpecifiedLocationColor(getApplicationContext(),
				text, (TextView) root.findViewById(R.id.tishi), getResources()
						.getColor(R.color.blue), index, minMoneyNumber);
		dialog.CreateDialog(MyDataActivity.this, root);
		// mpWindow = new PopupWindow(root, (int) getScreenSize(SCREENW), h);
		// mpWindow.setBackgroundDrawable(new BitmapDrawable());
		// mpWindow.setFocusable(true);
		// mpWindow.setTouchable(true);
		// mpWindow.setOutsideTouchable(true);
		// mpWindow.showAtLocation(findViewById(R.id.show), Gravity.CENTER, 0,
		// 0);
	}

	// 截取图片
	public void cropImage(Uri uri, int outputX, int outputY, int requestCode) {
		Intent intent = new Intent("com.android.camera.action.CROP");
		intent.setDataAndType(uri, "image/*");
		intent.putExtra("crop", "true");
		intent.putExtra("aspectX", 1);
		intent.putExtra("aspectY", 1);
		intent.putExtra("outputX", outputX);
		intent.putExtra("outputY", outputY);
		intent.putExtra("outputFormat", "JPEG");
		intent.putExtra("noFaceDetection", true);
		intent.putExtra("return-data", true);
		startActivityForResult(intent, requestCode);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.my_data_return_btn:
			MyDataActivity.this.finish();
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// 获取返回的字符串资源，（我的资料右边的）
		getReturnData(requestCode);
		//
		if (resultCode == Activity.RESULT_OK && requestCode == IMG_CROP_HEAD) {
			if (data != null) {
				if (data.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH) != null) {
					String picPath = data
							.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH);
					userDataSet.UserDataSet2(userInfoModel, 2, picPath, true);
				}
			}
		}
		if (resultCode == Activity.RESULT_OK && requestCode == IMG_CROP_BEIJING) {
			if (data != null) {
				// <<<<<<< .mine
				// if
				// (data.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH)
				// != null)
				//
				// {
				// =======
				if (data.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH) != null) {
					String picPath = data
							.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH);
					userDataSet.UserDataSet2(userInfoModel, 1, picPath, true);
				}
			}

		}

		//
		// if(!StringUtil.isNullOrEmpty(uri) && temp==0);
		// {
		// // iv_image.setImageURI(Uri.parse(uri));
		// userInfoModel.setHead(uri);
		// userDataSet.UserDataSet2(userInfoModel, 2, uri, true);
		//
		// }
		//

	}

	private void getReturnData(int requestCode) {
		// TODO Auto-generated method stub
		if (requestCode >= 1000 && requestCode != ErWeiMaZD) {
			Refresh();
		}
	}

	public void Refresh() {
		Intent intent = new Intent(MyDataActivity.this, MyDataActivity.class);
		intent.putExtra("uid", Utils.getUid(MyDataActivity.this));
		startActivity(intent);
		overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
		finish();
	}
	// /** 获得可以自己数据的数据显示在界面上 */
	// private void getReturnData(int requestCode) {
	// // TODO Auto-generated method stub
	// // String dt = data.getStringExtra("result");
	// for (int i = 0; i < TextOrimg_Id.length; i++) {
	// if ((i * 100 + i) == requestCode) {
	//
	// RefreshData();
	// }
	// }
	//
	// /*
	// * switch(rcode) { case MINGCHENG: Name.setText(dt); break; case EMAIL:
	// * E_mail.setText(dt); break; case SEX: Sex.setText(dt); break; case
	// * PHONEUMBER: PhoneNumber.setText(dt); break; case FROM:
	// * From.setText(dt); break; }
	// */
	// }
	// //下面三个方法finalBitmap对资源进行回收
	// @Override
	// protected void onResume() {
	// // TODO Auto-generated method stub
	// finalbitmap.setExitTasksEarly(false);
	// super.onResume();
	//
	//
	//
	// }
	// @Override
	// protected void onPause() {
	// // TODO Auto-generated method stub
	// finalbitmap.setExitTasksEarly(true);
	// super.onPause();
	//
	//
	// }
	//
	// @Override
	// protected void onDestroy() {
	// // TODO Auto-generated method stub
	// Utils.ExitPrgress(MyDataActivity.this);
	// finalbitmap.closeCache();
	// super.onDestroy();
	//
	//
	// }

}
